<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.common.effects.js" ></script>
    <script src="../libraries/RGraph.line.js" ></script>
    
    <title>A dynamically updating filled range chart with a threshold</title>
    
    <meta name="description" content="A dynamically updating filled range chart. The data here is simply generated randomly but could just as easily be retrieved from a server via AJAX (for example)." />
</head>
<body>

    <h1>A dynamically updating filled range chart with a threshold</h1>
    
    <p>
        This chart is very similar to the regular scrolling line chart but is a filled range chart with a threshold set.
    </p>

    <canvas id="cvs" width="1000" height="250">[No canvas support]</canvas>
    
    <script>

        window.onload = function (e)
        {
            var obj       = null;
            var numvalues = 300;
            var value     = 25;

            // RGraph.array_pad(array, length[, value])
            var data1 = RGraph.array_pad([], numvalues, null);
            var data2 = RGraph.array_pad([], numvalues, null);
        
            function drawGraph ()
            {
                // "cache" this in a local variable
                var _RG_ = RGraph;
                var canvas = document.getElementById("cvs");
                _RG_.Clear(canvas);
                

                if (!obj) {
                    obj = new RGraph.Line('cvs', data1, data2)
                        .Set('xticks', 100)
                        .Set('background.barcolor1', 'white')
                        .Set('background.barcolor2', 'white')
                        .Set('title.xaxis', 'Last 15-20 seconds')
                        .Set('title.yaxis', 'Bandwidth (MB/s)')
                        .Set('title.vpos', 0.5)
                        .Set('title', 'Bandwidth used')
                        .Set('title.yaxis.pos', 0.5)
                        .Set('title.xaxis.pos', 0.5)
                        .Set('colors', ['black'])
                        .Set('linewidth',0.5)
                        .Set('yaxispos', 'right')
                        .Set('ymax', 50)
                        .Set('xticks', 25)
                        .Set('filled', true)
                        .Set('filled.range', true)
                        .Set('filled.range.threshold', 25)
                        .Set('filled.range.threshold.colors', ['red','#0c0'])
                        .Set('fillstyle', 'red')
                        .Set('colors', ['black'])
                }

                
                value = value + _RG_.random(-3,3);
                value = Math.max(0,value)
                value = Math.min(50,value)
                
                obj.original_data[0].push(Math.min(value + 5, 50));
                obj.original_data[1].push(Math.max(value - 5, 0));
                
                obj.original_data[0] = _RG_.array_shift(obj.original_data[0]);
                obj.original_data[1] = _RG_.array_shift(obj.original_data[1]);
                
                obj.Draw();

                

                setTimeout(drawGraph, 50);
            }



            drawGraph();
        }
    </script>

    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>